﻿#ifndef  _DL_NET_DATA_H_
#define  _DL_NET_DATA_H_

#include "stdint.h"

typedef struct dl_frm_predat_s          dl_frm_predat_t;
typedef struct dl_protocol_data_s       dl_protocol_data_t;
typedef struct cmd_s                    cmd_t;

typedef int (*USER_DECODE_FN)(dl_protocol_data_t* iodata);
typedef int (*SEND_DATA_FN)(void* client, char* pdata, unsigned int len);
typedef void* (*CMD_HANDLER_FN)(void* client, unsigned int cmd);

#pragma pack(push,1)


#define  FRM_NOT_ENOUGH  -1

// net type
typedef enum
{
    NET_TYPE_UDP = 0,
    NET_TYPE_TCP,
    NET_TYPE_SP,
}enum_net_type;

struct dl_frm_predat_s
{
	unsigned short      ver;           // protocol version number
	unsigned long long  session;       // session id
	unsigned int        sn;            // frame serial number
	unsigned int        cmdid;         // 
};
struct dl_protocol_data_s
{
    void*               pnet;          // io handle
    uint8_t*            pcmd;          // frame
	int                 cmdlen;        // frame length
    uint8_t*            pdata;         // body
	int                 datalen;       // body length

	char                ip[16];        // net ip
	unsigned short      port;          // net port
	int                 sp;            // serial port

	int                 maxbuflen;     // max recv buf len
	int                 decode_ret;    // result of decode

    int                 net_type;      // type (net or serial)
    char                src[32];       // source

	unsigned short      ver;           // protocol version number
	unsigned long long  session;       // session id
	unsigned int        sn;            // frame serial number
	unsigned int        cmdid;         // 

	unsigned char       type;          // protocol type (user define)
    char                dev_sn[17];

	SEND_DATA_FN        send_data;     // send function

	CMD_HANDLER_FN      cmd_handler;   // cmd handler function
};

#pragma pack(pop)

#endif // #ifndef  _DL_NET_DATA_H_
